// 预期还款明细
app.controller('repayment', ['$scope', 'commonFactory', 'toaster', function ($scope, commonFactory, toaster) {
	var today = new Date()
	$scope.repaymentData = {
		dt:today
	}
    var requesrepayment = function () {
        if(!$scope.repaymentData.dt){
            toaster.pop('warning', '警告', '请选择日期');
            $scope.graybtn = false;
            return;
        }
        $scope.repaymentData.dt = commonFactory.DateFormat($scope.repaymentData.dt, 1);
        commonFactory.loading(true)
        commonFactory.ajax("/api/Product/RepayProductInfo", $scope.repaymentData, function (result) {
            commonFactory.loading(false)
            $scope.graybtn = false;
            if (result.Code == 1) {
                $scope.repaymentList = result.RepayProductInfoList;
            }
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    requesrepayment()
    $scope.query = function(){
        $scope.graybtn = true;
    	requesrepayment()
    }
    $scope.exportdetail = function(){
        if(!$scope.repaymentData.dt){
            toaster.pop('warning', '警告', '请选择日期');
            return;
        }
        $scope.repaymentData.dt = commonFactory.DateFormat($scope.repaymentData.dt, 1);
        $scope.gourl = commonFactory.baseurl + '/api/Product/ExcelRepayProductInfo?Dt=' + $scope.repaymentData.dt
    }
   
}]);
// 每日还款明细
app.controller('dayrepayment', ['$scope', 'commonFactory', 'toaster', '$modal', function ($scope, commonFactory, toaster, $modal) {
    var today = new Date()
    $scope.dayrepaymentData = {
        Index: 1,
        Size: 10,
        dt:today,
        ProductGroup:'0'
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.dayrepaymentData.Index >= $scope.page) {//判断最大页码
                $scope.dayrepaymentData.Index = $scope.page;
                return false;
            }
            $scope.dayrepaymentData.Index++
            requesdayrepayment();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.dayrepaymentData.Index <= 1) {//判断最小页码
            $scope.dayrepaymentData.Index = 1;
            return false;
        }
        $scope.dayrepaymentData.Index--;
        requesdayrepayment()
    }
    var requesdayrepayment = function () {
        if(!$scope.dayrepaymentData.dt){
            toaster.pop('warning', '警告', '请选择日期');
            $scope.graybtn = false;
            return;
        }
        $scope.dayrepaymentData.dt = commonFactory.DateFormat($scope.dayrepaymentData.dt, 1);
        commonFactory.loading(true)
        commonFactory.ajax("/api/product/RepayDetailInDay", $scope.dayrepaymentData, function (result) {
            commonFactory.loading(false)
            $scope.graybtn = false;
            if (result.Code == 1) {
                $scope.dayrepaymentList = result.Data.Dto;
                $scope.ListCount = result.Data.Total;
                $scope.page = Math.ceil(result.Data.Total / $scope.dayrepaymentData.Size);
            } else if (result.Code == 3) {
                toaster.pop('warning', '提示', result.Data);
            } else {
                toaster.pop('warning', '提示', '查询失败');
            }
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    requesdayrepayment()
    $scope.query = function(){
        $scope.graybtn = true;
        requesdayrepayment()
    }
    $scope.export = function(){
        if(!$scope.dayrepaymentData.dt){
            toaster.pop('warning', '警告', '请选择日期');
            return;
        }
        $scope.dayrepaymentData.dt = commonFactory.DateFormat($scope.dayrepaymentData.dt, 1);
        $scope.gourl = commonFactory.baseurl + '/api/product/ExcelRepayDetailInfoInDay?Dt=' + $scope.dayrepaymentData.dt+'&ProductGroup='+$scope.dayrepaymentData.ProductGroup+'&RepaymentItemId='
    }
    $scope.dayrepaymentDetail = function(RepaymentItemId){
        commonFactory.loading(true)
        commonFactory.ajax("/api/product/RepayDetailInfoInDay", {dt:'',ProductGroup:'0', RepaymentItemId: RepaymentItemId }, function (result) {
            commonFactory.loading(false)
            if (result.Code == 1) {
                var modalInstance = $modal.open({
                    templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
                    controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', '$timeout', function ($scope, $modalInstance, toaster, commonFactory, $timeout, items) {
                        $scope.drDetailshow = true;
                        $scope.drDetailList = result.Data;
                        $scope.exportdetail = function(){
                            $scope.exporturl = commonFactory.baseurl + '/api/product/ExcelRepayDetailInfoInDay?RepaymentItemId=' + RepaymentItemId + '&Dt=&ProductGroup=0'
                        }
                        $scope.cancel = function () {
                            $modalInstance.close('cancel');
                        };
                    }],
                    size: 'lg',
                    backdrop: false
                });

                modalInstance.result.then(function (selectedItem) { }, function () { });
            }
        }, function () {
            commonFactory.loading(false)
        }, "post");
    }
    
}]);

